MULBOOT_HEADER_FLAGS EQU 0x00010003
MULBOOT_HEADER2_MAGIC EQU 0xE85250D6 ;GRUB2 multiboot magic

global _start 
extern main 
[section .start.text] 
[bits 32] 
_start:
jmp _entry
ALIGN 8
mbt2_hdr:
dd MULBOOT_HEADER2_MAGIC
dd 0 ;architecture 0 - i386
dd mbt2_hdr_end - mbt2_hdr ; header_length
dd -(MULBOOT_HEADER2_MAGIC + 0 + (mbt2_hdr_end - mbt2_hdr))
dw 2, 0
dd 24
dd mbt2_hdr
dd _start
dd 0
dd 0
dw 3, 0
dd 12
dd _entry
dd 0
dw 0, 0
dd 8
mbt2_hdr_end:

ALIGN 8
_entry:
cli ;clear  interrupts
in al, 0x70 ;disable NMI
or al, 0x80
out 0x70,al
lgdt [GDT_PTR]
jmp dword 0x8 :_32bits_mode
_32bits_mode:
;initialize all registers needed by C
mov ax, 0x10
mov ds, ax
mov ss, ax
mov es, ax
mov fs, ax
mov gs, ax
xor eax,eax
xor ebx,ebx
xor ecx,ecx
xor edx,edx
xor edi,edi
xor esi,esi
xor ebp,ebp
xor esp,esp
;Initalize stack pointer register
mov esp,0x9000
call main
halt_step:
halt
jmp halt_step
GDT_START:
knull_dsc: dq 0
kcode_dsc: dq 0x00cf9e000000ffff
kdata_dsc: dq 0x00cf92000000ffff
k16cd_dsc: dq 0x00009e000000ffff
k16da_dsc: dq 0x000092000000ffff
GDT_END:
GDT_PTR:
GDTLEN dw GDT_END-GDT_START-1
GDTBASE dd GDT_START